package com.hisense.ovcloud.commons.tools;

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig;
import org.springframework.beans.factory.annotation.Value;

//@Component
public class ENCUtils {
    @Value("${enc.algorithm}")
    private String encAlgorithm;

    @Value("${enc.password}")
    private String encPassword;

    private EnvironmentStringPBEConfig config;
    private StandardPBEStringEncryptor encryptor;

    public ENCUtils() {
        //加密配置
        config = new EnvironmentStringPBEConfig();
        config.setAlgorithm(encAlgorithm);
        config.setPassword(encPassword);
        //加密工具
        encryptor = new StandardPBEStringEncryptor();
        encryptor.setConfig(config);
    }

    public String encrypt(String plaintext) {
        return encryptor.encrypt(plaintext);
    }

    public String decrypt(String encrypttext) {
        return encryptor.decrypt(encrypttext);
    }
}
